#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3005;
int n,m,up[N][N],dn[N][N],lt[N][N],rt[N][N];
char ch[N][N];
int ans = 0;
vector<int> vec[N];
int t[N],L,R;
#define lowbit(x) (x&(-x))
inline void add(int x,int v)
{
	for(;x<=R;x+=lowbit(x))
		t[x]+=v;
}
inline int ask(int x)
{
	int res = 0;
	for(;x>=L;x-=lowbit(x))
		res+=t[x];
	return res;
}
inline void solve(int l,int r,int x,int y)
{
	if(l>=r||x>=y) return;
	if(r-l>y-x)
	{
		int mid = (l+r)/2;
		for(int j = x;j<=y;j++)
		{
			L = max(up[mid][j],l),R = min(dn[mid][j],r);
			for(int k = L-1;k<=R;k++) t[k] = 0;
			for(int k = L;k<=R;k++)
				if(rt[k][j]>j)
				{
					add(k,1);
					if(rt[k][j]+1<=y) vec[rt[k][j]+1].push_back(k);
				}
			for(int k = j+1;k<=y;k++)
			{
				for(auto _:vec[k]) add(_,-1);
				vec[k].clear();
				int tmp = ask(mid);
				int cnt1 = tmp-ask(max({L,up[mid][k]})-1),cnt2 = ask(min({R,dn[mid][k]}))-tmp;
				ans+=cnt1*cnt2; 
			}
		}
		solve(l,mid,x,y);
		solve(mid+1,r,x,y);
	}
	else
	{
		int mid = (x+y)/2;
		for(int j = l;j<=r;j++)
		{
			L = max(lt[j][mid],x),R = min(rt[j][mid],y);
			for(int k = L-1;k<=R;k++) t[k] = 0;
			for(int k = L;k<=R;k++)
				if(dn[j][k]>j)
				{
					add(k,1);
					if(dn[j][k]+1<=r) vec[dn[j][k]+1].push_back(k);
				}
			for(int k = j+1;k<=r;k++)
			{
				for(auto _:vec[k]) add(_,-1);
				vec[k].clear();
				int tmp = ask(mid);
				int cnt1 = tmp-ask(max({lt[k][mid],L})-1),cnt2 = ask(min({rt[k][mid],R}))-tmp;
				ans+=cnt1*cnt2; 
			}
		}
		solve(l,r,x,mid);
		solve(l,r,mid+1,y);
	}
}
signed main()
{
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i = 1;i<=n;i++)
		for(int j = 1;j<=m;j++)
			cin>>ch[i][j];
	for(int i = 1;i<=n;i++)
	{
		int las = 1;
		for(int j = 1;j<=m;j++)
		{
			if(ch[i][j]!=ch[i][j+1])
			{
				for(int k = las;k<=j;k++)
					lt[i][k] = las,rt[i][k] = j;
				las = j+1;
			}
		}
	}
	for(int j = 1;j<=m;j++)
	{
		int las = 1;
		for(int i = 1;i<=n;i++)
		{
			if(ch[i][j]!=ch[i+1][j])
			{
				for(int k = las;k<=i;k++)
					up[k][j] = las,dn[k][j] = i;
				las = i+1;
			}
		}
	}
	solve(1,n,1,m);
	cout<<ans;
	return 0;
}

